/** Access Oracle database on Cheaval Through JDBC/ODBC driver.
   Notice that
	1. some ODBC driver may not work with JDBC/ODBC bridge. The ODBC Driver
	   for Oracle 8 doesn't work. The Microsoft ODBC driver for Oracle works fine.
	2. You have to create data source name (DSN) with ODBC Data Source in Control
	   Panel.

   The Basic steps to access database:

	1. Load database driver (JDBC/ODBC driver, or thin driver):
		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	2. Connect to database system:
		Connection cnn = DriverManager.getConnection(url,usr,pwd);
	3. Create a Statement object from the Connection object:
		Statement stmt = cnn.createStatement();
	4. Create a ResultSet object by calling executeQuery( sql )
	   from the Statement object:
		ResultSet rs = stmt.executeQuery("Select * from Emp");
	5. Access rows in result set, and for each row access each field/column with
		two nested loop.
   Do the first three steps in a constructor, and repeatedly do the last two steps to
   execute multiple SQL statements.
*/
import java.sql.*;

public class AccessChevalDB1
{
     public static void main(String args[])
     {
	  String url = "jdbc:odbc:chevalDB1";
          String usr = "scott";
	  String pwd = "tiger";
	  String rec = null;
	  int i;
	
	  try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); }
	  catch(java.lang.ClassNotFoundException e) { e.printStackTrace(); }

	  try
	  {
		Connection cnn = DriverManager.getConnection(url,usr,pwd);

		Statement stmt = cnn.createStatement();

		ResultSet rs = stmt.executeQuery("Select * from Emp");
		System.out.println("\n\nData from Cheval through JDBC/ODBC Driver\n");
		while(rs.next()) {
			rec = "";
			for (i = 1; i < 9; i++)
			 	rec += rs.getString(i) + " ";
			System.out.println(rec);
		}
		stmt.close();
		cnn.close();
	}
	catch(SQLException e)
	{
		System.out.println(e.toString());
		e.printStackTrace();

	}
     }
}
